package com.droid.lib.controls.demo.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;

import com.droid.lib.controls.demo.R;
import com.droid.lib.controls.widget.RippleView;

import java.util.ArrayList;

public class MenuAdapter extends BaseAdapter {
	private Context mContext;
	ArrayList<String> strs = new ArrayList<String>();
	private OnClicker clicker;

	public interface OnClicker {
		public void onclick(int position);

	}

	public MenuAdapter(Context mContext) {
		this.mContext = mContext;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return strs.size();
	}

	public void setOnClicker(OnClicker clicker) {
		this.clicker = clicker;
	}

	public void setList(ArrayList<String> strs) {
		this.strs = strs;
	}

	@Override
	public String getItem(int position) {
		// TODO Auto-generated method stub
		return strs.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@SuppressLint({ "ViewHolder", "ResourceAsColor" })
	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		View view = LinearLayout.inflate(mContext, R.layout.list_menu, null);
		RippleView text = (RippleView) view.findViewById(R.id.text);
		text.setRippleColor(android.R.color.white, 0.2f);
		text.setHover(true);
		text.init();
		text.setText(strs.get(position));
		text.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				clicker.onclick(position);
			}
		});
		return view;
	}

}
